#include "character.h"

#include <iostream>
using namespace std;

#include "dice.h"
#include "combat.h"


character::character(const char * character_name, stats * initial_stats):
	name(character_name),
	victim(0),
	director(0),
	my_stats(*initial_stats) 
{
}

void character::hit(int attack_roll, int target_defence, int damage)
{
	if (attack_roll >= my_stats.defences[target_defence]) {
	
		my_stats.current_hit_points -= damage;
		cout << name << " takes " << damage << " hit points of damage" << endl;
	}

	if (my_stats.current_hit_points < 1) {

		director->character_has_died(this);
	}
}

void character::fight_now() { 

	cout << name << " makes an attack" << endl; 
	int hit_roll = roll(20) + my_stats.attack_bonus;
	int damage_roll = roll(my_stats.damage_dice) + my_stats.damage_bonus;
	victim->hit(hit_roll, AC, damage_roll);
}

void character::output_name() 
{ 
	cout << name; 
}

void character::target(combat * this_fight, character * chosen_target) {

	director = this_fight;
	victim = chosen_target;
}
